# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def kthLargest(self, root: TreeNode, k: int) -> int:
        def add(node):
            if node is not None:
                add(node.right)
                self.k -= 1
                if not self.k: # 只需要每个节点判断一次
                    self.res = node.val
                add(node.left)
        
        self.k = k
        add(root)
        return self.res